<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="90px">
      <el-form-item label="消息标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="消息标题"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['robot:groupmsg:add']"
        >新增
        </el-button>
      </el-col>
    </el-row>

    <el-table border v-loading="loading" :data="list" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="所属群组" align="center" prop="groupName"/>
      <el-table-column label="发送机器人" align="center" prop="botName"/>
      <el-table-column label="消息标题" align="center" prop="title"/>
      <el-table-column label="消息内容" align="center" prop="msg"/>
      <el-table-column label="发送时间" align="center" prop="sendTime"/>
      <el-table-column label="发送状态" align="center" prop="sendStatus" >
        <template slot-scope="scope">
          {{ scope.row.sendStatus === 0?"未发送":scope.row.sendStatus === 1?"已发送":"发送失败"}}
        </template>
      </el-table-column>
      <el-table-column label="是否重试" align="center" prop="sendRetry">
        <template slot-scope="scope">
          {{ scope.row.sendRetry?"不重试":"重试"}}
        </template>
      </el-table-column>
      <el-table-column label="消息类型" align="center" prop="topType">
      <template slot-scope="scope">
        {{ scope.row.topType?"顶置消息":"普通消息"}}
      </template>
      </el-table-column>
      <el-table-column label="顶置时长" align="center" prop="effectiveTime"/>
      <el-table-column label="创建时间" align="center" prop="createTime"/>
      <el-table-column fixed="left" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['robot:groupmsg:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['robot:groupmsg:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>

    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改公司信息对话框 -->
    <groupDialog ref="groupDialog" @close="getList"/>
  </div>
</template>

<script>
import {add, del, getList, getOneById, update} from "@/api/bot/groupmsg";
import groupDialog from "@/views/robot/groupmsg/groupDialog.vue";

export default {
  name: "groupmsg",
  components: {groupDialog},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 机器人信息表格数据
      list: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
      },

    };
  },
  created() {
    this.getList();
  },
  methods: {

    /** 查询公司信息列表 */
    getList() {
      this.loading = true;
      getList(this.queryParams).then(response => {
        this.list = response.records;
        this.total = response.count;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.groupDialog.initFun();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id || this.ids
      this.$refs.groupDialog.initFun(id);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除公司信息编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return del(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      }).catch(function () {
      });
    },
    statusTransform(row){

    },

  }
};
</script>
